package com.omt.tarjimdinek.domain.user.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.Size;

import org.apache.log4j.Logger;
import org.hibernate.annotations.Check;
import org.hibernate.validator.constraints.NotEmpty;

import com.google.common.base.Objects;
import com.omt.tarjimdinek.support.Identifiable;

/**
 * validate an account
 * @author chabane
 *
 */
@Entity
@Table(name="a01_vldmbr")
public class ValidationMembre implements Identifiable<Long>, Serializable{

    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(ValidationMembre.class);
    
    /** Validate a subscription */
    public static final String VALIDER_INSCRIPTION = "VALIDER_INSCRIPTION";
    
    /** Get my password */
    public static final String RECUPERER_MOT_DE_PASSE = "RECUPERER_MOT_DE_PASSE";
    
	/** ID SGBD */
	@Column(name="CNVLDMBR", length=11)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
	/** ID SGBD */
	@Column(name="CNEMAIL", nullable=false, length=3)
	@NotEmpty
	private String email;
	
	@Column(name = "VERSION", precision = 10)
    @Version
    private Integer version;
	
	/** Unique key **/
	@Size(max = 36)
	@NotEmpty
	@Column(name="LIUUID", length=36, nullable=false, unique=true)
	private String uuid;
	
	/** Check if account is validated */
	@Column(name="BOVLD")
	private Boolean validated;
	
	/** type of validation */
	@Column(name="LITYVA")
	@Check(constraints = "LITYVA IN ('VALIDER_INSCRIPTION','RECUPERER_MOT_DE_PASSE')")
	private String typeValidation;
	
	@Transient
	public boolean isIdSet() {
	    return id != null && id.compareTo(Long.valueOf(0)) != 0;
	}
	
	/**
     * equals implementation using a business key.
     */
	@Override
	public boolean equals(Object other) {
	    return (other instanceof ValidationMembre) && (id != null)
	        ? id.equals(((ValidationMembre) other).id)
	        : (other == this);
	}

	@Override
	public int hashCode() {
	    return (id != null)
	        ? (this.getClass().hashCode() + id.hashCode())
	        : super.hashCode();
	}
    
    /**
     * Set the default values.
     */
    public void initDefaultValues() {
    }
    
    /**
     * Construct a readable string representation for this Account instance.
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return Objects.toStringHelper(this) //
        		.add("id", getId()) //
                .add("email", getEmail()) //
                .add("UUID", getUuid()) //
                .add("typeValidation", getTypeValidation()) //
                .toString();
    }

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the version
	 */
	public Integer getVersion() {
		return version;
	}

	/**
	 * @param version the version to set
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}

	/**
	 * @return the uuid
	 */
	public String getUuid() {
		return uuid;
	}

	/**
	 * @param uuid the uuid to set
	 */
	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	/**
	 * @return the validate
	 */
	public Boolean getValidated() {
		return validated;
	}

	/**
	 * @param validate the validate to set
	 */
	public void setValidated(Boolean validate) {
		this.validated = validate;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the typeValidation
	 */
	public String getTypeValidation() {
		return typeValidation;
	}

	/**
	 * @param typeValidation the typeValidation to set
	 */
	public void setTypeValidation(String typeValidation) {
		this.typeValidation = typeValidation;
	}
}
